﻿<infrastructure:VisualStateAwarePage x:Class="AdventureWorks.Shopper.Views.ShippingAddressPage"
                                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                     xmlns:local="using:AdventureWorks.Shopper.Views"
                                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                     xmlns:infrastructure="using:Microsoft.Practices.Prism.StoreApps"
                                     x:Uid="Page"
                                     mc:Ignorable="d"
                                     infrastructure:ViewModelLocator.AutoWireViewModel="true">
    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!-- Back button, page title and subtitles-->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    Style="{StaticResource BackButtonStyle}"
                    Command="{Binding GoBackCommand}" />
            <TextBlock x:Name="pageTitle"
                       Grid.Column="1"
                       Text="{Binding HeaderLabel}"
                       IsHitTestVisible="false"
                       Style="{StaticResource PageHeaderTextStyle}" />
        </Grid>

        <!-- Settings Panel Content -->
        <ScrollViewer VerticalScrollBarVisibility="Auto"
                      Grid.Row="1"
                      ZoomMode="Disabled">
            <Grid x:Name="contentGrid" 
                  Margin="120,10,0,50"
                  VerticalAlignment="Top"
                  HorizontalAlignment="Left"
                  MaxWidth="600"
                  MinWidth="600"
                  Grid.RowSpan="3">

                <StackPanel x:Name="stackPanel" HorizontalAlignment="Stretch">
                    <local:ShippingAddressUserControl x:Name="shippingAddressUC"
                                                      Grid.Column="2"
                                                      Grid.Row="1"
                                                      Loaded="StartLayoutUpdates"
                                                      Unloaded="StopLayoutUpdates"
                                                      DataContext="{Binding ShippingAddressViewModel}" />
                    <Button x:Name="button" x:Uid="SaveButton"
                            AutomationProperties.AutomationId="SaveButton"
                            Content="Save"
                            Background="{StaticResource AWShopperAccentBrush}"
                            MinWidth="300"
                            Margin="0,50,20,20"
                            HorizontalAlignment="Right"
                            Command="{Binding SaveCommand}"/>
                </StackPanel>
            </Grid>
        </ScrollViewer>
        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="DefaultLayout" />
                <VisualState x:Name="PortraitLayout">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20,10" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.MinWidth)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Stretch" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="MinimalLayout">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource MinimalBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource MinimalPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20,10" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.MinWidth)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)"
                                                       Storyboard.TargetName="contentGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Stretch" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="button">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <HorizontalAlignment>Stretch</HorizontalAlignment>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</infrastructure:VisualStateAwarePage>